<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/StoresSystem' }">首页</el-breadcrumb-item>
      <!-- <el-breadcrumb-item :to="{ path: '/StoresSystem/ShopsList' }">门店列表</el-breadcrumb-item> -->
      <el-breadcrumb-item>查看库存</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="bians">
      <el-input placeholder="请输入查询内容" v-model="search.searchValue" class="input-with-select">
        <el-select v-model="search.searchType" slot="prepend" placeholder="请选择">
          <el-option label="商品名字" value="name"></el-option>
          <el-option label="商品价格" value="price"></el-option>
          <el-option label="商品数量" value="num"></el-option>
        </el-select>
        <el-button slot="append" icon="el-icon-search" @click="serchGoods"></el-button>
      </el-input>
    </div>
    <el-table size="small" :data="allGoods" style="width: 100%" height="370px">
      <el-table-column label="商品编号" prop="_id" width="190%"></el-table-column>
      <el-table-column label="商品名字" prop="name"></el-table-column>
      <el-table-column label="商品价格" prop="price"></el-table-column>
      <el-table-column label="商品数量" prop="num"></el-table-column>
      <el-table-column label="商品门店" prop="shopsId.name"></el-table-column>
      <el-table-column label="商品图片">
        <template slot-scope="scope">
          <img class="studentsImage" :src="scope.row.imagePath" />
        </template>
      </el-table-column>
      <el-table-column label="操作">

        <template slot-scope="scope">
          <el-button size="small" @click="updateGoods(scope.row)">修改</el-button>

          <el-dialog title="修改信息" :visible.sync="centerDialogVisible">
            <el-form :model="getUpdateGood">
              <el-form-item label="商品名字：">
                <el-input autocomplete="off" v-model="getUpdateGood.name"></el-input>
              </el-form-item>
              <el-form-item label="商品价格：">
                <el-input autocomplete="off" v-model="getUpdateGood.price"></el-input>
              </el-form-item>
              <el-form-item label="商品数量：">
                <el-input autocomplete="off" v-model="getUpdateGood.num"></el-input>
              </el-form-item>
              <el-form-item label="商品门店：">
                <el-select v-model="getUpdateGood.shopsId._id" placeholder="请选择商品门店">
                  <el-option 
                  v-for="item in allShops"
                  :key="item._id"
                  :label="item.name"
                  :value="item._id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-form>
             <div slot="footer" class="dialog-footer">
              <el-button @click="centerDialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="updata(getUpdateGood)" :plain="true">确 定</el-button>
            </div>
          </el-dialog>

           <el-button size="mini" type="danger" @click="deleteGoods(scope.row._id)" :plain="true">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange3"
        @current-change="handleCurrentChange3"
        :current-page="pageData3.currentPage"
        :page-sizes="[4,5,6,7]"
        :page-size="pageData3.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData3.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { createNamespacedHelpers } from "vuex";
const {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("finishedGoods");

export default {
  data() {
    return {
      search: {
        searchType: "",
        searchValue: ""
      },
      centerDialogVisible: false,
      getUpdateGood: {
        name: "",
        price: "",
        num: "",
        shopsId: ""
      },
      shopsData:{}
    };
  },
  computed: {
    ...mapState(["pageData3","allShops","allGoods"])
  },
  created() {
    this.getGoodsCellAsync();
    this.getShops()
    console.log(this.allGoods)
    // console.log(this.pageData);
  },
  methods: {
    ...mapMutations(["changepageSize", "changePage"]),
    // ...mapMutations(["updateStudents", "close"]),
    ...mapActions([
      "getGoodsCellAsync",
      "deleteGoodsCellAsync",
      "updataGoodsCellAsync",
      "deleteGoods",
      "getShops",
      "handleCurrentChange3",
      "handleSizeChange3",
    ]),
    //点击修改按钮
    updateGoods(row) {
      this.centerDialogVisible = true;
      this.getUpdateGood = {...row}
      console.log(row)
    },

    //下架
    removeGoods(row) {
      this.deleteGoodsCellAsync(row._id);
      this.$message({
        showClose: true,
        message: "下架成功",
        type: "success"
      });

      this.getGoodsCellAsync();
    },
    //分页
    // handleCurrentChange(val) {
    //   this.changePage(val);
    //   this.getGoodsCellAsync();
    // },
    // handleSizeChange(val) {
    //   // console.log(`每页 ${val} 条`);
    //   this.changepageSize(val);
    //   this.getGoodsCellAsync();
    // },
    // 点击修改改变数据
    updata(newGoodData) {
      console.info(newGoodData)
      this.updataGoodsCellAsync({ ...newGoodData });
      //  this.getGoodsCellAsync();
      this.$message({
        showClose: true,
        message: "修改成功",
        type: "success"
      });
      this.centerDialogVisible = false;
    },
    //
    serchGoods() {
      console.log();
      //  this.getStudentsAsync()
      this.getGoodsCellAsync(this.search);
    }
  }
};
</script>

<style>
.el-breadcrumb {
  padding-left: 10px;
  height: 30px;
}

.el-table__header-wrapper .has-gutter tr th {
  line-height: 60px;
}
.has-gutter .cell {
  text-align: center;
  font-size: 14px;
}
.el-table__row .cell {
  text-align: center;
}
.is-right button {
  margin-right: 5px;
}
.el-dialog {
  width: 440px;
}
.el-form-item {
  padding: 0 40px;
}
.el-dialog__header {
  display: flex;
}
.el-dialog .el-input {
  width: 260px;
}
.el-dialog__close {
  display: none;
}
.dialog-footer {
  padding-right: 40px;
}

.el-pagination {
  margin-top: 10px;
  height: 30px !important;
}
.studentsImage {
  width: 50px;
}
.el-select .el-input {
  width: 130px;
}
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}
.bans {
  line-height: 60px;
}


.el-table_1_column_6 .cell img{
  width: 50px !important;
  height: 50px !important;
}
</style>